﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Api
{
    /// <summary>
    /// 加入活动
    /// </summary>
    class JoinActivityAction : AuthPostAction<Params.JoinActivityParams,
        Results.JoinActivityResult>
    {
        protected override ActionResult<Results.JoinActivityResult> OnExecute(ActionContext context, SysParameters sysParameters,
            Params.JoinActivityParams opParams)
        {
            JizSport.Common.Logger.DebugToTag(LogTag.TAG, "JoinActivityAction account:{0} activity:{1}", context.AccountId,
                opParams.ActivityId);
            
            ServiceResult<string> serviceResult = new ActivityService().Join(context.AccountId,
                opParams.ActivityId);

            Results.JoinActivityResult actionResult = new Results.JoinActivityResult();

            if (serviceResult.ErrorCode == ErrorCode.NoError)
            {
                return new ActionResult<Results.JoinActivityResult>("1.0.2", true, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
            }
            return new ActionResult<Results.JoinActivityResult>("1.0.3", false, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
        }
    }
}
